package com.hw01.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import com.hw01.common.Result;
import com.hw01.common.ResultPage;
import com.hw01.dto.ChangePasswordDto;
import com.hw01.dto.EmployeeAddDto;
import com.hw01.dto.EmployeeQueryDto;
import com.hw01.dto.EmployeeUpdateDto;
import com.hw01.service.EmployeeService;
import com.hw01.vo.EmployeeVo;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

import java.util.List;

/**
 * 员工用户
 **/
@RestController
@Api("员工管理")
@RequestMapping("/employee")
public class EmployeeController {

    @Autowired
    EmployeeService employeeService;

    @GetMapping("/one")
    @ApiOperation("按id获取员工信息")
    @ResponseBody
    public Result<EmployeeVo> getEmployeeById(@ApiParam(value = "员工id", required = true) Long id) {
        return employeeService.getEmployeeById(id);
    }

    @PostMapping("/changePwd")
    @ApiOperation("修改密码")
    public Result<Boolean> changePassword(@RequestBody ChangePasswordDto dto) {
        return employeeService.changePassword(dto);
    }

    @PostMapping("/page")
    @ApiOperation("按条件查询员工信息(分页)")
    @ResponseBody
    public ResultPage<EmployeeVo> getEmployeePage(@RequestBody EmployeeQueryDto dto) {
        return employeeService.getEmployeePage(dto);
    }

    @PostMapping("/add")
    @ApiOperation("新增员工信息")
    public Result<Boolean> add(@RequestBody EmployeeAddDto dto) {
        return employeeService.add(dto);
    }

    @PostMapping("/update")
    @ApiOperation("修改员工信息")
    public Result<Boolean> update(@RequestBody EmployeeUpdateDto dto) {
        return employeeService.update(dto);
    }

    @GetMapping("/del")
    @ApiOperation("删除员工信息")
    public Result<Boolean> delete(@ApiParam(value = "员工id", required = true) Long id) {
        return employeeService.delete(id);
    }

    @PostMapping("/uploadPhotoAvatar")
    @ApiOperation("用户上传头像")
    public Result<String> uploadPhotoAvatar(
        @ApiParam(value = "员工id", required = true) @RequestParam("userId") Long userId,
        @ApiParam(value = "头像", required = true) @RequestParam("file") MultipartFile file) {
        return employeeService.uploadPhotoAvatar(userId, file);
    }

    @PostMapping("/byOrg")
    @ApiOperation("查询部门下的所有人员")
    public Result<List<EmployeeVo>> getEmployeeByOrgId(
            @ApiParam(value = "部门id", required = true) @RequestParam("orgId") Long orgId) {
        return employeeService.getEmployeeByOrgId(orgId);
    }

}
